// src/store/toast.js
import { defineStore } from 'pinia'

export const useToastStore = defineStore('toast', {
  state: () => ({
    toasts: [] // { id, message, type }
  }),
  actions: {
    // 显示 toast
    showToast(message, type = 'info') {
      const id = Date.now() + Math.floor(Math.random() * 1000)
      this.toasts.push({ id, message, type })

      // 自动关闭
      setTimeout(() => {
        this.removeToast(id)
      }, 3000)
    },
    removeToast(id) {
      this.toasts = this.toasts.filter(t => t.id !== id)
    }
  }
})
